.\" Man page generated from reStructuredText.
.
.TH "GAMMU-SMSD-RUN" "7" "Oct 03, 2020" "1.42.0" "Gammu"
.SH NAME
gammu-smsd-run \- documentation for RunOnReceive directive
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.SH DESCRIPTION
.sp
Gammu SMSD can be configured by \fBRunOnReceive\fP directive (see
gammu\-smsdrc for details) to run defined program after receiving
every message. It can receive single message or more messages, which are parts
of one multipart message.
.sp
This parameter is executed through shell, so you might need to escape some
special characters and you can include any number of parameters. Additionally
parameters with identifiers of received messages are appended to the command
line. The identifiers depend on used service backend, typically it is ID of
inserted row for database backends or file name for file based backends.
.sp
Gammu SMSD waits for the script to terminate. If you make some time consuming
there, it will make SMSD not receive new messages. However to limit breakage
from this situation, the waiting time is limited to two minutes. After this
time SMSD will continue in normal operation and might execute your script
again.
.sp
\fBNOTE:\fP
.INDENT 0.0
.INDENT 3.5
All input and output file descriptors are closed when this program is
invoked, so you have to ensure to open files on your own.
.UNINDENT
.UNINDENT
.SH ENVIRONMENT
.sp
New in version 1.28.0.

.sp
Program is executed with environment which contains lot of information about
the message. You can use it together with NULL service (see
gammu\-smsd\-null) to implement completely own processing of messages.
.SS Global variables
.INDENT 0.0
.TP
.B SMS_MESSAGES
Number of physical messages received.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_PARTS
Number of decoded message parts.
.UNINDENT
.INDENT 0.0
.TP
.B PHONE_ID
New in version 1.38.2.

.sp
Value of \fBPhoneID\fP\&. Useful when running multiple instances
(see smsd\-multi).
.UNINDENT
.SS Per message variables
.sp
The variables further described as \fBSMS_1_...\fP are generated for each physical
message, where 1 is replaced by current number of message.
.INDENT 0.0
.TP
.B SMS_1_CLASS
Class of message.
.UNINDENT
.INDENT 0.0
.TP
.B SMS_1_NUMBER
Sender number.
.UNINDENT
.INDENT 0.0
.TP
.B SMS_1_TEXT
Message text. Text is not available for 8\-bit binary messages.
.UNINDENT
.INDENT 0.0
.TP
.B SMS_1_REFERENCE
New in version 1.38.5.

.sp
Message Reference. If delivery status received, this variable contains TPMR of original message
.UNINDENT
.SS Per part variables
.sp
The variables further described as \fBDECODED_1_...\fP are generated for each message
part, where 1 is replaced by current number of part. Set are only those
variables whose content is present in the message.
.INDENT 0.0
.TP
.B DECODED_1_TEXT
Decoded long message text.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_1_MMS_SENDER
Sender of MMS indication message.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_1_MMS_TITLE
title of MMS indication message.
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_1_MMS_ADDRESS
Address (URL) of MMS from MMS indication message.
.sp
\fBSEE ALSO:\fP
.INDENT 7.0
.INDENT 3.5
faq\-mms\-download
.UNINDENT
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B DECODED_1_MMS_SIZE
Size of MMS as specified in MMS indication message.
.UNINDENT
.SH EXAMPLES
.SS Activating RunOnReceive
.sp
To activate this feature you need to set \fBRunOnReceive\fP in
the gammu\-smsdrc\&.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
[smsd]
RunOnReceive = /path/to/script.sh
.ft P
.fi
.UNINDENT
.UNINDENT
.SS Processing messages from the files backend
.sp
Following script (if used as \fBRunOnReceive\fP handler) passes
message data to other program. This works only with the gammu\-smsd\-files\&.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
#!/bin/sh
INBOX=/path/to/smsd/inbox
PROGRAM=/bin/cat
for ID in "$@" ; do
    $PROGRAM < $INBOX/$ID
done


.ft P
.fi
.UNINDENT
.UNINDENT
.SS Invoking commands based on message text
.sp
Following script (if used as \fBRunOnReceive\fP handler) executes
given programs based on message text.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
#!/bin/sh

# Check for sender number
if [ "$SMS_1_NUMBER" != "+420123456789" ] ; then
    exit
fi

# Handle commands
case "$SMS_1_TEXT" in
    "DMS A")
        /usr/bin/dms\-a
        ;;
    "DMS B")
        /usr/bin/dms\-b
        ;;
esac

.ft P
.fi
.UNINDENT
.UNINDENT
.SS Passing message text to program
.sp
Following script (if used as \fBRunOnReceive\fP handler) passes
message text and sender to external program.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
#!/bin/sh
PROGRAM=/bin/echo
for i in \(gaseq $SMS_MESSAGES\(ga ; do
    eval "$PROGRAM \e"\e${SMS_${i}_NUMBER}\e" \e"\e${SMS_${i}_TEXT}\e""
done

.ft P
.fi
.UNINDENT
.UNINDENT
.SS Passing MMS indication parameters to external program
.sp
Following script (if used as \fBRunOnReceive\fP handler) will write
information about each received MMS indication to the log file. Just replace
echo command with your own program to do custom processing.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
#!/bin/sh
if [ $DECODED_PARTS \-eq 0 ] ; then
    # No decoded parts, nothing to process
    exit
fi
if [ "$DECODED_1_MMS_ADDRESS" ] ; then
    echo "$DECODED_1_MMS_ADDRESS" "$DECODED_1_MMS_SENDER" "$DECODED_1_MMS_TITLE" >> /tmp/smsd\-mms.log
fi

.ft P
.fi
.UNINDENT
.UNINDENT
.SS Processing message text in Python
.sp
Following script (if used as \fBRunOnReceive\fP handler) written
in Python will concatenate all text from received message:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
#!/usr/bin/env python
from __future__ import print_function
import os
import sys

numparts = int(os.environ[\(aqDECODED_PARTS\(aq])

text = \(aq\(aq
# Are there any decoded parts?
if numparts == 0:
    text = os.environ[\(aqSMS_1_TEXT\(aq]
# Get all text parts
else:
    for i in range(1, numparts + 1):
        varname = \(aqDECODED_%d_TEXT\(aq % i
        if varname in os.environ:
            text = text + os.environ[varname]

# Do something with the text
print(\(aqNumber %s have sent text: %s\(aq % (os.environ[\(aqSMS_1_NUMBER\(aq], text))

.ft P
.fi
.UNINDENT
.UNINDENT
.SH AUTHOR
Michal Čihař <michal@cihar.com>
.SH COPYRIGHT
2009-2015, Michal Čihař <michal@cihar.com>
.\" Generated by docutils manpage writer.
.
